package com.atguigu05.communication;

//采用继承的方式
class PrintNumber extends Thread {

    static int number = 1;
    static Object obj = new Object();//使用同一把锁
    @Override
    public void run() {
        while (true) {
            synchronized (PrintNumber.class) {

                PrintNumber.class.notify();

                if(number <= 100) {
                    System.out.println(Thread.currentThread().getName() + ":" + number);
                    number++;
                    try {
                        PrintNumber.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    break;
                }
            }


        }
    }
}
public class PrintNumberTest {
    public static void main(String[] args) {
        PrintNumber printNumber = new PrintNumber();
        PrintNumber printNumber1 = new PrintNumber();

        printNumber.start();
        printNumber1.start();
    }
}
